package com.lucaswangdev.controller;

import com.lucaswangdev.common.AjaxResult;
import com.lucaswangdev.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public AjaxResult findAll(){
        return AjaxResult.success(userService.findAll());
    }

    @RequestMapping("/success1")
    public AjaxResult success1() {
        return AjaxResult.success();
    }

    @RequestMapping("/success2")
    public AjaxResult success2() {
        return AjaxResult.success("xxx成功");
    }

    @RequestMapping("/success3")
    public AjaxResult success3() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("name", "张三");
        map.put("age", 18);
        return AjaxResult.success(map);
    }

    @RequestMapping("/error1")
    public AjaxResult error1() {
        return AjaxResult.error();
    }

    @RequestMapping("/error2")
    public AjaxResult error2() {
        return AjaxResult.error("xxx错误");
    }
}
